﻿using ConfExpert.Forms.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using DevTeam;
using DevExpress.XtraGrid.Views.Grid;

namespace ConfExpert.Forms.Depo.Kauf
{
    public partial class ModelhaneBMIstek : XForm
    {
        private String SatirListesi;
        private const int StandardSapmaEsigi = 250;
        public ModelhaneBMIstek(String SatirListesi)
        {
            InitializeComponent();
            this.SatirListesi = SatirListesi;
        }

        private void ModelhaneBMIstek_Load(object sender, EventArgs e)
        {
            this.Text = "Modelhaneden Birim Metraj Talebi";
            gridView1.Init("GetModelhaneBirimMetraj2", SatirListesi);
            
            gridView1.MakeColumnInvisible("StdSapma");
            gridView1.MakeReadOnly("RevisedEn", "RaporBoyuId", "DesenYonuId");

            gridView1.RowCellStyle += gridView1_RowCellStyle;
            
            gridView1.BestFitColumns();

        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (((GridView)sender).GetRowCellValue(e.RowHandle, "StdSapma").ToInt() > StandardSapmaEsigi)
                if(e.Column.FieldName.Equals("EnListesi"))
                    e.Appearance.ForeColor = System.Drawing.Color.Red;
        }

        private void bbiKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            string TableXml = gridView1.SerializeChanges();

            ExecuteNonQuery("UpdModelhaneBirimMetraj3", TableXml, SatirListesi);

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
